home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 January: Mac OS SDK / Dev.CD Jan 96 SDK / Dev.CD Jan 96 SDK1.toast / Development Kits (Disc 1) / QuickDraw™ GX / Programming Stuff / Sample Code / Graphics Samples / Grayscale Bitmap ƒ / Grayscale Bitmap.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-10  |  4.3 KB  |  148 lines  |  [TEXT/KAHL]

  1. /*
  2.     Grayscale Bitmap.c
  3.  
  4.     This file contains the calls to create a bitmap shape from scratch. It will create a 1 pixel high by 256 pixel gxWide grayscale bitmap.  
  5.     We will then scale the bitmap shape by 60 in the y direction. 
  6.     
  7.     NOTE:
  8.     • This file requires the following files to run correctly:
  9.         "graphics shell.c", "graphics debug library.c", "transform library.c".
  10.  
  11.     • For the best printing results, print this file in "landscape".
  12.     
  13.     
  14.     ©1992 - 1994 Apple Computer, Inc.
  15.     All rights reserved.
  16. */
  17.  
  18. #include <events.h>
  19. #include <windows.h>
  20.  
  21. #include "graphics debugging.h"
  22. #include "graphics libraries.h"
  23. #include "graphics toolbox.h"
  24. #include "graphics shell.h"
  25.  
  26. //
  27. //      Set up the title and size of the window 
  28. //
  29. Str255         gWindowTitle = "\p Grayscale Bitmap ";
  30. Rect         gWindowQDRect  = {50, 20, 170, 345};
  31.  
  32. //
  33. //    gGraphicsHeapSize sets the size of the graphics gxHeap created by calling the GXNewGraphicsClient routine
  34. //    in main () within graphics shell.c.  You can determine the amount of graphics gxHeap required by using GraphicsBug.
  35. //    With  gGraphicsHeapSize set to 60k, I had 7 free blocks left in the graphics gxHeap. Sounds good to me.
  36. //
  37. long        gGraphicsHeapSize = 60;
  38.  
  39.  
  40. gxShape     gBitShape;
  41.  
  42.  
  43. /*------ DoInitialization ---------------------------------------------------------------------------------*/
  44.  
  45. void DoInitialization(gWindow)
  46. WindowPtr gWindow;
  47. {
  48.     char        bitImage[256];
  49.     gxBitmap    theBitmapData;
  50.     gxPoint        theBitmapPosition;
  51.     short        loop; 
  52.     gxColor        grayPixelColor;
  53.  
  54.     gxViewPort    windowViewPortParent;
  55.  
  56.     //
  57.     //    Get the gxViewPort that is attached to the window, and set the dither of this gxViewPort to 4.  Which
  58.     //    will mean that all objects that are drawn into window will be dithered at a dither level of 4.
  59.     //
  60.      windowViewPortParent = GXGetWindowViewPort(gWindow);
  61.     GXSetViewPortDither(windowViewPortParent, 4);
  62.  
  63.     //
  64.     //    Define gBitShape's starting position
  65.     //
  66.     theBitmapPosition.x = theBitmapPosition.y = ff(25);
  67.  
  68.     //
  69.     //    Define the gBitShape's structure. It will be a bitmap shape which is 1 pixel high and 256 pixels wide.
  70.     //    We will attach a gray color space below.
  71.     //
  72.     theBitmapData.image     = bitImage;
  73.     theBitmapData.width     = 256;
  74.     theBitmapData.height     = 1;
  75.       theBitmapData.rowBytes     = 256;
  76.     theBitmapData.pixelSize = 8;
  77.     theBitmapData.space     = gxNoSpace;
  78.     theBitmapData.set         = nil;
  79.     theBitmapData.profile     = nil;
  80.     
  81.     grayPixelColor.space = gxGraySpace;
  82.     grayPixelColor.profile = nil;
  83.     
  84.     gBitShape = GXNewBitmap (&theBitmapData, &theBitmapPosition);
  85.     GXSetShapeAttributes (gBitShape, gxMemoryShape);
  86.  
  87.     //
  88.     //    Create a gray pixel gxColor and change the value of the pixel within our bitmap shape. Starting with the first
  89.     //    pixel within our bitmap shape and moving to the right.
  90.     //
  91.     for (loop = 0; loop <= 255; ++loop) {
  92.         grayPixelColor.element.gray = (loop << 8);
  93.         GXSetShapePixel (gBitShape , loop, 0, &grayPixelColor, 0);
  94.     }  
  95.  
  96.     //
  97.     //    Scale our bitmap shape - gBitShape by 60 in the y direction. This will grow the height of the shape by 40.
  98.     //
  99.     GXScaleShape (gBitShape, fixed1, ff(60), theBitmapPosition.x, theBitmapPosition.y);
  100. }
  101.  
  102.  
  103. /*------ DoDraw ---------------------------------------------------------------------------------------*/
  104.  
  105. void DoDraw(gWindow)
  106. WindowPtr gWindow;
  107. {
  108.     GXDrawShape (gBitShape);
  109. }
  110.  
  111.  
  112. /*------ DoDispose -------------------------------------------------------------------------------------*/
  113.  
  114. void DoDispose(gWindow)
  115. WindowPtr gWindow;
  116. {
  117.     /**  
  118.         You should always dispose of your GX graphics objects before tossing your window. Why? It's generally good 
  119.         form and this approach guarantees that everything is disposed. If you had not disposed of everything, the
  120.         call to DisposeWindow should dispose of the objects. If you are running the debugging version of the 
  121.         SecretGraphics init with notices set, you will receive a notice that you had not disposed of everything. You
  122.         can turn notices on in this file by setting gDebugging = TRUE (above).
  123.     **/
  124.     GXDisposeShape(gBitShape);  
  125.      GXDisposeShape(gWindowBoundsShape);  
  126.        DisposeWindow(gWindow);
  127. }
  128.     
  129.  
  130. /*------ DoIdle ----------------------------------------------------------------------------------------*/
  131.  
  132. void DoIdle(gWindow)
  133. WindowPtr gWindow;
  134. {
  135. }
  136.  
  137.  
  138. /*------ DoClick ---------------------------------------------------------------------------------------*/
  139.  
  140. void DoClick( orgMouseLoc, theWindow )
  141. gxPoint        orgMouseLoc;
  142. WindowPtr     theWindow;
  143. {
  144. }
  145.  
  146.  
  147.  
  148.